# -*- coding: utf-8 -*-
"""
@Author: Logan
@Date:   2025/7/11 14:50
@Description: 
"""
from base.ObjectMap import ObjectMap
from base.TradingMarketBase import TradingMarketBase
from selenium.webdriver.common.by import By

from logs.log import log


class TradingMarketPage(TradingMarketBase, ObjectMap):
    def input_search_input(self, driver, input_value):
        """
        输入搜索宝贝输入框
        :param driver:
        :param input_value:
        :return:
        """
        log.info("搜索宝贝输入框输入" + input_value)
        search_input_xpath = self.search_input()
        return self.element_fill_value(driver, By.XPATH, search_input_xpath, input_value)

    def click_search(self, driver):
        """
        点击搜索按钮
        :param driver:
        :return:
        """
        log.info("点击搜索按钮")
        search_xpath = self.search_button()
        return self.element_click(driver, By.XPATH, search_xpath)

    def click_goods_card(self, driver, goods_title):
        """
        点击商品卡片
        :param driver:
        :param goods_title:
        :return:
        """
        log.info(f"点击{goods_title}卡片")
        goods_card_path = self.goods_card(goods_title)
        return self.element_click(driver, By.XPATH, goods_card_path)

    def click_i_want_button(self, driver):
        """
        点击我想要按钮
        :param driver:
        :return:
        """
        log.info("点击我想要按钮")
        i_want_button_path = self.i_want_button()
        self.scroll_to_element(driver, By.XPATH, i_want_button_path)
        return self.element_click(driver, By.XPATH, i_want_button_path)

    def input_goods_nums(self, driver, nums):
        """
        输入购买商品数量
        :param driver:
        :param nums:
        :return:
        """
        log.info(f"购买{nums}件商品")
        goods_nums_xpath = self.goods_nums()
        return self.element_fill_value(driver, By.XPATH, goods_nums_xpath, nums)

    def click_address(self, driver):
        """
        点击收货地址
        :param driver:
        :return:
        """
        log.info("点击收货地址")
        receive_xpath = self.receive_address()
        return self.element_click(driver, By.XPATH, receive_xpath)

    def select_receive_address(self, driver, num, address=None):
        """
        选择具体收获地址
        :param driver:
        :param num:
        :param address:
        :return:
        """
        if address:
            log.info("选择具体收货地址:" + address)
            address_xpath = self.receive_address_detail(0, address=address)
        else:
            log.info("选择第" + str(num) + "个收货地址")
            address_xpath = self.receive_address_detail(num)
        return self.element_click(driver, By.XPATH, address_xpath)

    def click_bottom_button(self, driver):
        """
        点击确定按钮
        :param driver:
        :return:
        """
        log.info("点击确定按钮:")
        button_xpath = self.bottom_confirm()
        return self.element_click(driver, By.XPATH, button_xpath)


